package com.pan.server.mapper;

import com.pan.pojo.dto.BookDTO;
import com.pan.pojo.entity.Book;
import com.pan.pojo.vo.BookVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface BookMapper {

    /**
     * 查询所有书籍
     * @return
     */
    @Select("select * from book")
    List<BookVO> queryBooks();

    /**
     * 根据条件查询书籍
     * @param bookDTO
     * @return
     */
    List<BookVO> searchBooks(BookDTO bookDTO);

    /**
     * 根据id查询价格
     * @param id
     * @return
     */
    @Select("select price from book where book_id = #{id}")
    int searchPriceById(Integer id);

    /**
     *
     * @param orderId
     * @return
     */
    @Select("select stock from book where book_id = (select book_id from order_detail where order_id = #{orderId})")
    int queryBookStock(Integer orderId);

    /**
     * 根据订单id查询书籍id
     * @param orderId
     * @return
     */
    @Select("select book_id from order_detail where order_id = #{orderId}")
    int queryBookIdByOrderId(Integer orderId);

    /**
     * 添加书籍
     * @param book
     */
    void addBook(Book book);

    /**
     * 删除书籍
     * @param id
     */
    @Delete("delete from book where book_id = #{id}")
    void deleteBook(Integer id);

    /**
     * 更新书籍信息
     * @param book
     */
    void updateBook(Book book);
}